class Solution {
public:
    vector<int> findSwapValues(vector<int>& array1, vector<int>& array2) {
        vector<int> ret;
        int sum1 = 0,sum2 = 0;
        int n = array2.size();
        
        for(int& i : array1){
            sum1 += i;
        }
        for(int& j : array2){
            sum2 += j;
        }
        
        int ans = sum1 - sum2;
        
        sort(array2.begin(),array2.end());
        for(int& i : array1){
            int l = 0;
            int r = n-1;
            while(l <= r){
                int m = l + (r - l) / 2;
                
                int path = (i - array2[m]) * 2;
                if(path > ans){
                    l = m+1;
                }else if(path < ans){
                    r = m-1;
                }else{
                    ret.push_back(i);
                    ret.push_back(array2[m]);
                    return ret;
                }
            }
        }
        return ret;
    }
};
